import characterTools from "shared/component/common/characterTools";
import Log4R from "shared/component/log/Log4R";
import { resource } from "shared/component/resource/resource";
import { CharacterServiceImpl } from "shared/modules/character/service/CharacterServiceImpl";
const loginfo = Log4R.getLog('info');
export class CharacterServerServiceImpl extends CharacterServiceImpl {

    public loadCharacter(characterEntity: Ctn.character.PlayerCharacterEntity) {
        const player = characterEntity.player
        if (player) {
            player.CharacterAdded.Connect((character) => {
                // character.ChildAdded.Connect(c => {
                //     loginfo?.info('character add:', c)
                // })
                character.WaitForChild('Animate').Destroy();
                const humanModel = character as Ctn.character.HumanModel;
                characterEntity.character = humanModel
                this.creatCharacterEventBinder.callBack(characterEntity)
            })
            const bonePath = characterEntity.bonePath || "C9Q5";
            const starterCharacter = characterTools.createCharacter(bonePath);
            // loginfo?.info('starterCharacter', starterCharacter)
            if (starterCharacter?.IsA('Model')) {
                starterCharacter.Name = "StarterCharacter";
                game.GetService('StarterPlayer').FindFirstChild("StarterCharacter")?.Destroy();
                starterCharacter.Parent = game.GetService('StarterPlayer')

            }

            player.LoadCharacter();
        }


    }
    /** 创建角色后触发 */
    syncPlayerCharacter(param: Ctn.character.PlayerCharacterEntity, session: Ctn.Session) {
        this.fire('syncPlayerCharacter', param, session)

    }

}